#include "LinerEqus.h"
using namespace std;

int main()
{
    int M, N;
    char char_continue;                                     //循环计算标志
    cout << "Please enter the M " << endl;//and N:"<< endl;
    cin >> M;
    //cin >> N;
    N = M;                                                  //temp
    LinerEqus linerequs(M, N);                              //初始化
    double **a = NULL;      								//线性方程组的系数矩阵
    double **b = NULL;      								//线性方程组的常数矩阵
    double **x = NULL;      								//线性方程组的解

    do
    {
        cout << "Coefficient Matrix" << endl;
        a = linerequs.SetMatrix(M, N, 1);       //动态建立系数矩阵a,并手工输入数据

        cout << "Constant Matrice" << endl;
        b = linerequs.SetMatrix(M, 1, 1);       //动态建立常数矩阵b,并手工输入数据

        cout << "xxxxxxxx" << endl;
        x = linerequs.SetMatrix(N, 1, 0);       //建立N*1数组存放解x,但不输入数据

        linerequs.CpArray(a, linerequs.m_a, M, N);				//保存a的初始矩阵值,用于LUTure
        linerequs.CpArray(b, linerequs.m_b, M, N);				//保存b的初始矩阵值,用于LUTure

        cout << "=========   111   ===========" << endl;
        linerequs.PrintMatrix(a, M, N);       	            //打印a
        linerequs.PrintMatrix(b, M, 1);       	            //打印b
        cout << "=========   222   ===========" << endl;
        linerequs.PrintMatrix(linerequs.m_a, M, N);       	//打印m_a
        linerequs.PrintMatrix(linerequs.m_b, M, 1);       	//打印m_b


        cout << "=============step1 start============" << endl;
        linerequs.LUDec(a, b, M, N);						//将a化为上三角矩阵,LU伪
        linerequs.Solve(a, b, x, M, N);					    //求解x
        cout << "=============step1 end=============" << endl;

        cout << "=============step2 start============" << endl;
        linerequs.LUTure(linerequs.m_a, linerequs.m_b, linerequs.m_x, M, N );   //LU分解法
        cout << "=============step2 end=============" << endl;

        cout << "=========   333   ===========" << endl;
        linerequs.PrintMatrix(a, M, N);         //打印a
        linerequs.PrintMatrix(x, N, 1);       	//打印x
        cout << "=========   444   ===========" << endl;
        linerequs.PrintMatrix(linerequs.m_a, M, N);       //打印m_a
        linerequs.PrintMatrix(linerequs.m_x, N, 1);       //打印m_x


        linerequs.FreeMatrix(a, M, N);        	//释放a
        linerequs.FreeMatrix(b, M, 1);        	//释放b
        linerequs.FreeMatrix(x, N, 1);        	//释放x

        linerequs.m_ivec.clear();
        linerequs.true_flag = 0;

        cout << "Please enter Y or y to continue!" << endl;
        cin >> char_continue;
    }
    while (char_continue == 'Y' || char_continue == 'y' );

    linerequs.~LinerEqus();
    return 0;
}
